<?php

namespace App\Http\Middleware;

use Closure;
use App\Common\ApiToken;

class CheckTokenSome
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //1.检查是否缺少token
        $token = $request->header('Authorization','');
        $apiToken   = new ApiToken();
        if($apiToken && $apiToken->check_token($token) == true)
        {
            $request->offsetSet("tokenUserId",$apiToken->tokenInfo->user_id);
        }
        else
        {
            $request->offsetSet("tokenUserId",0);
        }

        return $next($request);
    }
}
